package com.controller.wmt;

import com.dao.HousestatusDao;
import com.entity.House;
import com.entity.HouseDetail;
import com.entity.HouseList;
import com.entity.Housestatus;
import com.service.wmt.BuildManagerService;
import com.service.wmt.HouseService;
import com.service.wmt.HouseStatusService;
import com.util.gzp.AjaxResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("buildManager")
public class BuildManagerContoller {
    @Resource
    private BuildManagerService buildManagerService;
    @Resource
    private HouseStatusService houseStatusService;
    @Resource
    private HouseService houseService;

    @RequestMapping("listAllNoPage")
    @ResponseBody
    public AjaxResponse listAllNoPage(){

        AjaxResponse ajaxResponse = AjaxResponse.success(buildManagerService.findAllHouse());
        return ajaxResponse;
    }

    /*
		查询所有楼盘信息分页
		 */
    @RequestMapping("listAll")
    @ResponseBody
    public AjaxResponse listAll(Integer pageNum,Integer pageSize){

        AjaxResponse ajaxResponse = AjaxResponse.success(buildManagerService.findAll(pageNum,pageSize));
        return ajaxResponse;
    }

    /**
     * 楼盘详细信息展示
     *
     * @return
     */

    /**
     *
     * @param hid
     * @return
     */
    @ResponseBody
    @RequestMapping("detail")
    public AjaxResponse findHouseDetailByHid(Integer hid){
        HouseDetail houseDetail = buildManagerService.findHouseDetailByHid(hid);
        AjaxResponse ajaxResponse = AjaxResponse.success(houseDetail);
        return ajaxResponse;
    }

    /***
     * 按照名称查找楼盘
     * @param hname
     * @return
     */
    @ResponseBody
    @RequestMapping("findByName")
    public AjaxResponse findByName(String hname){
        List<HouseList> houseList= new ArrayList<>();

        if(hname.length()!=0){
            houseList = buildManagerService.findByName("%"+hname+"%");

        }else {
            houseList=buildManagerService.findAllHouse();
        }

        return AjaxResponse.success(houseList);
    }
    @ResponseBody
    @RequestMapping("getAllHouseStatus")
    public AjaxResponse getAllHouseStatus(){
        List<Housestatus> list = houseStatusService.findAll();
        AjaxResponse ajaxResponse = AjaxResponse.success(list);
        return ajaxResponse;
    }


    @RequestMapping("houseDetail")
    @ResponseBody
    public AjaxResponse houseDetail(){
        AjaxResponse ajaxResponse = AjaxResponse.success();
        return ajaxResponse;
    }
    @RequestMapping("addHousesss")
    @ResponseBody
    public AjaxResponse addHouse(House house){
        System.out.println("BuildManagerContoller.addHouse"+house);
        Integer i = houseService.insert(house);
        return AjaxResponse.success(i);
    }

}
